package codeRandomThoughts.Test198打家劫舍;

import java.util.Arrays;

/**
 * 一遍AC
 */
public class Solution {
    public int rob(int[] nums) {
        //dp[i]:偷窃0~i号房屋最多能偷多少钱
        int[] dp = new int[nums.length];

        //初始化
        dp[0] = nums[0];

        for (int i = 1; i < nums.length; i++) {
            int tem = 0;
            if (i >= 2) {
                tem = dp[i - 2];
            }
            dp[i] = Math.max(tem + nums[i], dp[i - 1]);
        }

        System.out.println(Arrays.toString(dp));
        return dp[nums.length - 1];
    }
}
